package com.jmb.apiplatform.controller;


import com.jmb.apiplatform.common.Result;
import com.jmb.apiplatform.exception.ValidException;
import com.jmb.apiplatform.pojo.PermissionDao;
import com.jmb.apiplatform.pojo.PermissionTO;
import com.jmb.apiplatform.service.PermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "权限管理")
@Slf4j
@RequestMapping("/permission")
@RestController
public class PermissionController{
    @Autowired
    private PermissionService permissionService;

    @Operation(summary = "新增权限")
    @PostMapping("/save")
    public Result save(@RequestBody PermissionDao permissionDao) throws ValidException {
        permissionService.savePermission(permissionDao);
        return Result.success("新增成功");
    }
    @Operation(summary = "查询权限")
    @GetMapping
    private Result listPermission( ) {
        List<PermissionTO> list = permissionService.findPermission(0);
        return Result.success(list);
    }
    @Operation(summary = "修改权限")
    @PostMapping("/modify")
    public Result modifyPermission(@RequestBody PermissionDao permissionDao) throws ValidException {
        permissionService.modifyPermission(permissionDao);
        return Result.success("修改成功");
    }
    @Operation(summary = "删除权限")
    @GetMapping("/remove/{id}")
    public Result removePermission(@PathVariable Integer id) throws ValidException {
        log.info("接受的id是{}",id);
        permissionService.removeById(id);
        return Result.success("删除成功");
    }

}
